<template>
	<view class="p20">
		<view class="radius20 ov-h mb20">
			<u-tabs :list="tabs" :is-scroll="false" :current="current" @change="e=>current=e"></u-tabs>
		</view>
		<u-empty mode="list" v-if="!list.length" />
		<view class="bg-fff radius20 p20 mb20" v-for="(item,index) in list" :key="index">
			<view class="flex border-b pb20 fs30">
				<view class="flex1 fw-w u-line-1">{{item.name}}提交的申请</view>
				<view class="">{{item.add_time}}</view>
			</view>
			<view class="mt24 color-666">开始时间：{{item.start_time}}</view>
			<view class="mt24 color-666">结束时间：{{item.end_time}}</view>
			<view class="mt24 color-666 flex col-top">
				<view class="">申请原因：</view>
				<text>{{item.reason}}</text>
			</view>
			<view class="flex row-between mt30">
				<block v-if="$params.admin&&item.status==0">
					<view class="w326">
						<u-button type="warning" ripple plain @click="stopVerify(item.id,2)">拒绝</u-button>
					</view>
					<view class="w326">
						<u-button type="warning" ripple @click="stopVerify(item.id,1)">同意</u-button>
					</view>
				</block>
				<view class="w326" v-else-if="item.status==0">
					<u-button type="warning" ripple plain @click="cancel(item.id)">取消</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//状态:-1全部,0申请中,1已通过,2已拒绝,3已取消
				tabs: [{
					name: '全部',
					status: '-1'
				}, {
					name: '申请中',
					status: '0'
				}, {
					name: '已通过',
					status: '1'
				}, {
					name: '已拒绝',
					status: '2'
				}, {
					name: '已取消',
					status: '3'
				}],
				current: 0,
				list: '',
			};
		},
		watch: {
			current(e) {
				this.getList()
			},
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			this.getList('down')
		},
		methods: {
			getList(e) {
				e == 'down' ? this.page++ : this.page = 1
				let params = {
					page: this.page,
					status: this.tabs[this.current]?.status || '-1'
				}
				let api='/master/my/stopList'
				if(this.$params.admin)api='/master/my/stopManageList'
				this.$request(api, params).then(res => {
					let list = res.data.data
					e == 'down' ? this.list.push(...list) : this.list = list
				})
			},
			cancel(stop_id) { //取消申请
				this.$showModal("取消申请").then(res => {
					this.$request('/master/my/cancel', {
						stop_id
					}).then(res => {
						this.$msg(res.msg)
						this.getList()
					})
				})
			},
			stopVerify(stop_id, status) { //暂停接单申请-同意/拒绝
				this.$showModal(status==1?"同意申请":'拒绝申请').then(res => {
					this.$request('/master/my/stopVerify', {
						stop_id,
						status,
					}).then(res => {
						this.$msg(res.msg)
						this.getList()
					})
				})
			},

		}
	}
</script>

<style lang="scss">

</style>
